<?php

class timuxuanxiangModule extends Model
{
    public function __construct()
    {
        parent::__construct("timuxuanxiang");
    }

    /**
     * 查题目关键词
     * @date: 2019年6月24日 上午10:51:35
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getKeywordsByids($ids)
    {
        $list = $this->find("id,guanjianci")->where("id in ({$ids}) ")->all();
        $keyWords = "";
        foreach ($list as $k => $v) {
            if ($keyWords == "") {
                $keyWords = $v["guanjianci"];
            } else {
                $keyWords = $keyWords . "," . $v["guanjianci"];
            }
        }

        if ($keyWords != "") {
            //分割关键词
            $returnArray = [];
            $keyWordArray = explode(',', $keyWords);
            foreach ($keyWordArray as $k => $v) {
                $v = explode('=', $v);
                //$keyWordArray[$k]=$v;
                if (Count($v) > 1) {
                    $returnArray[$v[0]] = $v[1];
                } else {
                    $returnArray[$v[0]] = 0.01;
                }
            }
            return $returnArray;
        } else {
            return [];
        }

    }

    /**
     * 提取json里的题目选项ID
     * @date: 2019年6月24日 上午11:02:30
     * @param:  [{"timu":"1","xuanxiang":"2"},{"timu":"2","xuanxiang":"3"}]
     * @return:
     * @author: 龚华尧
     */
    public function getIdsByJsonstr($data)
    {
        $xuanxiangid = "";
        foreach ($data as $k => $v) {
            if ($xuanxiangid == "") {
                $xuanxiangid = $v["xuanxiang"];
            } elseif ($this->common->isNumber($v["xuanxiang"])) {
                $xuanxiangid = $xuanxiangid . "," . $v["xuanxiang"];
            }
        }
        return $xuanxiangid;
    }
}